package com.ruoyi.test.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.test.domain.Message;
import com.ruoyi.test.serv.IMessageServ;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/hello/message")
public class MessageController {
    @Resource
    private IMessageServ IMessageServ;

    @PostMapping("/add")
    public void add(@RequestBody Message dto){
        IMessageServ.add(dto);
    }

    @GetMapping("/selectAll")
    public PageInfo<Message> selectAll(@RequestParam("senderId") String senderId,
                                       @RequestParam(value = "receiverId", required = false) String receiverId,
                                       @RequestParam(value = "toChannelName", required = false) String toChannelName,
                                       @RequestParam(defaultValue = "1") int pageNum,
                                       @RequestParam(defaultValue = "5") int pageSize){
        // 使用PageHelper开始分页
        PageHelper.startPage(pageNum, pageSize);
        List<Message> messages = IMessageServ.selectAll(senderId, receiverId, toChannelName);
        return new PageInfo<>(messages);
    }
}
